<template>
	<view class="jnpf-wrap jnpf-wrap-workflow">
		<u-form :model="info" ref="dataForm" :errorType="['toast']" label-position="left" label-width="150"
			label-align="left">
			<u-form-item label="部门经理" v-if="judgeShow('udf13')">
				<view v-for="(item, index) in udf13Name" :key="index" style="margin-left: 5px">
					<u-tag :text="item" type="success" />
				</view>
			</u-form-item>
			<u-form-item label="采购人员" v-if="judgeShow('udf01')">
				<view v-for="(item, index) in udf01Name" :key="index" style="margin-left: 5px">
					<u-tag :text="item" type="success" />
				</view>
			</u-form-item>
			<u-divider color="#fa3534" type='warning'>资产请购单</u-divider>
			<u-form-item label="请购单别" v-if="judgeShow('ti001')">
				<u-input v-model="info.ti001" placeholder="请购单别" :disabled="judgeWrite('ti001')"></u-input>
			</u-form-item>
			<u-form-item label="请购单号" v-if="judgeShow('ti002')">
				<u-input v-model="info.ti002" placeholder="请购单号" :disabled="judgeWrite('ti002')"></u-input>
			</u-form-item>
			<u-form-item label="请购部门" v-if="judgeShow('ti006')">
				<u-tag :text="ti006Name" type="success" />
			</u-form-item>
			<u-form-item label="单据日期" v-if="judgeShow('ti004')">
				<u-input v-model="info.ti004" placeholder="单据日期" :disabled="judgeWrite('ti004')"></u-input>
			</u-form-item>
			<u-form-item label="请购人员" v-if="judgeShow('ti007')">
				<u-tag :text="ti007Name" type="success" />
			</u-form-item>
			<u-form-item label="备注" v-if="judgeShow('ti008')">
				<u-input v-model="info.ti008" placeholder="备注" :disabled="judgeWrite('ti008')"></u-input>
			</u-form-item>
			<u-divider color="#fa3534" type='warning' v-if="info.asttjList!=0">详细信息</u-divider>
			<view class="jnpf-table" style="margin-top: 24rpx;">
				<view class="jnpf-table-item" style="margin-bottom: 24rpx;" v-for="(item,i) in info.asttjList" :key="i">
					<u-form-item label="序号">
						{{i+1}}
					</u-form-item>
					<u-form-item label="品号" v-if="judgeShow('asttjList-tj004')">
						<u-input v-model="item.tj004" placeholder="品号"
							:disabled="judgeWrite('asttjList-tj004')"></u-input>
					</u-form-item>
					<u-form-item label="规格" v-if="judgeShow('asttjList-tj005')">
						<u-input v-model="item.tj005" placeholder="规格"
							:disabled="judgeWrite('asttjList-tj005')"></u-input>
					</u-form-item>
					<u-form-item label="单位" v-if="judgeShow('asttjList-tj006')">
						<u-input v-model="item.tj006" placeholder="单位"
							:disabled="judgeWrite('asttjList-tj006')"></u-input>
					</u-form-item>
					<u-form-item label="供应商" v-if="judgeShow('asttjList-tj008')">
						<u-input v-model="item.tj008" placeholder="供应商"
							:disabled="judgeWrite('asttjList-tj008')"></u-input>
					</u-form-item>
					<u-form-item label="请购数量" v-if="judgeShow('asttjList-tj007')">
						<u-input v-model="item.tj007" placeholder="请购数量"
							:disabled="judgeWrite('asttjList-tj007')"></u-input>
					</u-form-item>
					<u-form-item label="需求日期" v-if="judgeShow('asttjList-tj009')">
						<u-input v-model="item.tj009" placeholder="需求日期"
							:disabled="judgeWrite('asttjList-tj009')"></u-input>
					</u-form-item>
					<u-form-item label="备注" v-if="judgeShow('asttjList-tj018')">
						<u-input v-model="item.tj018" placeholder="备注"
							:disabled="judgeWrite('asttjList-tj018')"></u-input>
					</u-form-item>

				</view>
			</view>
		</u-form>
	</view>
</template>

<script>
	import {
		getAstti
	} from '@/api/workFlow/flowEngine'
	import {
		getDataInterfaceDataInfo,
		getDictionaryDataSelector,
		getDataInterfaceRes,
		getUserAll,
		Interface,
	} from '@/api/common'

	import comMixin from '../mixin'
	import {
		getGoodsList,
		getCustomerList,
		Info,
		Create,
		Update
	} from '@/api/apply/order'
	export default {
		name: 'crmOrder',
		mixins: [comMixin],
		data() {
			return {
				dataForm: {},
				id: '',
				info: {},
				udf13Name: [],
				udf01Name: [],
				ti006Name: '',
				ti007Name: '',
			}
		},

		methods: {
			init(data, id, flowFormContentJson) {
				this.setting = data
				this.id = id
				this.getInfo(data)
			},
			getInfo(data) {
				getAstti(data.id).then(res => {
					if (res.code == 200) {
						this.info = res.data
						this.getUser()
						this.getDepartment(this.info.ti006)
						this.getPersonnel(this.info.ti007)
					}
				})
			},
			getUser() {
				getUserAll().then((res) => {
					this.udf13Name = res.data.filter((item) => this.info.udf13.includes(item.id)).map((item) =>
						item.realName);
					this.udf01Name = res.data.filter((item) => this.info.udf01.includes(item.account)).map((
							item) =>
						item.realName);
				});
			},
			// 获取部门
			getDepartment(id) {
				let interfaceId = '362111557984852549'
				let data = {
					id,
					interfaceId,
					propsValue: 'ME001',
					relationField: 'JoinStr',
				}
				getDataInterfaceDataInfo(interfaceId, data).then(res => {
					this.ti006Name = res.data.JoinStr;
				})
			},
			// 获取人员
			getPersonnel(id) {
				let interfaceId = '438122284524265733'
				let data = {
					id,
					interfaceId,
					propsValue: 'MV001',
					relationField: 'JoinStr',
				}
				getDataInterfaceDataInfo(interfaceId, data).then(res => {
					this.ti007Name = res.data.JoinStr;
				})
			},
			selfGetInfo() {
				Info(this.setting.id).then(res => {
					this.dataForm = res.data
					if (this.dataForm.fileJson) {
						this.fileList = JSON.parse(this.dataForm.fileJson)
					}
				})
			},
			selfSubmit() {
				this.dataForm.status = this.eventType === 'submit' ? 0 : 1
				if (this.eventType === 'save') return this.selfHandleRequest()
				uni.showModal({
					title: '提示',
					content: '您确定要提交当前流程吗？',
					success: res => {
						if (res.confirm) {
							this.selfHandleRequest()
						}
					}
				})
			},
			selfHandleRequest() {
				if (!this.dataForm.id) delete(this.dataForm.id)
				const formMethod = this.dataForm.id ? Update : Create
				formMethod(this.dataForm).then(res => {
					uni.showToast({
						title: res.msg,
						complete: () => {
							setTimeout(() => {
								uni.$emit('refresh')
								uni.navigateBack()
							}, 1500)
						}
					})
				})
			},
			initData() {
				getGoodsList().then(res => {
					this.goodsOptions = res.data.list
				})
				getCustomerList().then(res => {
					this.customerOptions = res.data.list
				})
			},
		}
	}
</script>